<div id="tabsdetail">
  <div id="tab1" class="tabcontents">
    <form action="javascript:void(0)" id="check_order_form" method="post">
      <div class="hd">
        <h2>hóa đơn bán hàng</h2>
        <div class="sub-form">
          <label>Người lập
            <input type="text" name="" id="order_user" value="<?php echo $_SESSION['ses_user']; ?>" size="28" />
          </label>
        </div>
        <div class="sub-form">
          <?php $date = time();?>
          <label>Ngày lập
            <input type="text" name="" id="order_date" value="<?php echo(date("d - m - Y",$date));  ?>" size="28" />
          </label>
        </div>
        <div class="sub-form">
          <label>Số bàn
            <input type="text" name="" id="order_table" value="<?php echo $data['info']['soban']; ?>" size="5">
          </label>
        </div>
        <table>
          <thead>
            <tr>
              <th>STT</th>
              <th>Tên sản phẩm</th>
              <th>Số lượng</th>
              <th>Đơn giá</th>
              <th>Thành tiền</th>
              <th>Mua</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>0</td>
              <td><select id="order_name">
                  <option value="0" class="0"> -- Chọn sản phẩm -- </option>
                  <?php
						if(isset($data['list_pro']) && $data['list_pro'] != NULL){
							$stt = 0;
							foreach($data['list_pro'] as $items){
								$stt++;
								echo '<option class="order_qtys_'.$stt.'" value="'.$items['masanpham'].','.$items['dongiaban'].'">'.$items['tensanpham'].'</option>';
							}
						}
					?>
                </select></td>
              <td class="quty"><input type="text" class="quyti" id="qty" name="s_quantity" value="1">
                <button class="minus" type="button"></button>
                <button class="plus" type="button"></button>
                <script type="text/javascript">
					//sô lượng giỏ hàng
					jQuery(document).ready(function($) {
						var quyti = $(".quyti").val();
					
						$(".minus").click(function(event) {
							quyti = parseInt(quyti) + 1;
							$(".quyti").val(quyti);
							
							pro_qty = $("#qty").val();
							pro_price = $(".pro_price").val();
							total = pro_qty * pro_price;
							$("#total_one").text(total);
						});
					
						$(".plus").click(function(event) {
							quyti = parseInt(quyti) - 1;
							if(quyti < 1){
								alert("số lượng không thể nhỏ hơn 1");
								$(".quyti").val(1);
							}else{
								pro_qty = $("#qty").val();
								pro_price = $(".pro_price").val();
								total = pro_qty * pro_price;
								$("#total_one").text(total);
								$(".quyti").val(quyti);
								
							}
						});
					});

				</script>
              </td>
              <td><input type="text" size="10" value="0" class="pro_price"></td>
              <td><span id="total_one">0</span></td>
              <td><input type="submit" id="cafe_buy" style="font-weight:bold" name="ok" value="Thêm" /></td>
            </tr>
            <tr>
              <td style="border:none" colspan="6"></td>
            </tr>
            <tr>
              <td style="border:none" colspan="6"><div class="cart_view"></div></td>
            </tr>
            <?php
				$total = 0;
				//debug($_SESSION['cart2']);
				if(isset($_SESSION['cart2']) && $_SESSION['cart2']  != NULL){
				$stt = 0;
				foreach($_SESSION['cart2'] as $key => $value){
					$stt++;
			?>
            <tr class="bachnx_all_row" style="padding-top:20px;">
              <td><?php echo $stt; ?></td>
              <td><?php echo $value['name']; ?></td>
              <td><?php echo $value['qty']; ?></td>
              <td><?php echo @number_format($value['price'])." VNĐ"; ?></td>
              <td><?php $total_1 = ($value['price'] * $value['qty']);  echo @number_format($total_1)." VNĐ" ;?></td>
              <?php if($_SESSION['ses_level'] == 1){ ?>
              <td><a href="<?php echo base_url ;?>index.php?mod=order&act=del_ses_cart&pid=<?php echo $value['id']; ?>&cid=<?php echo $data['id']; ?>&type=one" id="cafe_buy" style="font-weight:bold" onclick="return confirm('Bạn có muốn xóa không?');" />Xóa</a></td>
              <?php }else{ ?>
              	<td><a href="javascript:void(0)" id="cafe_buy" style="font-weight:bold" onclick="return confirm('Bạn không được phép xóa?');" />Xóa</a></td>
              <?php }?>
            </tr>
            <?php $total = $total + $total_1 ;?>
            <?php } } ?>
          <input type="hidden" name="total_cate_price" id="total_cate_price" value="<?php echo $total ?>" />
          </tbody>
          
        </table>
        <script type="text/javascript">
			$(document).ready(function(e){
				$("#check_order_form").change(function(){
					alls = $("#order_name").val();
					pro_id = alls.substr(0,2);
					pro_price = alls.substr(3,10);
					//pro_id = $(".order_name").v("class");
					//alert(pro_price); return false;
					pro_qty = $("#qty").val();
					pro_name = $(".order_qtys").html();
					$(".pro_price").val(pro_price);
					if(pro_qty == 0){
						alert("Vui lòng nhập số lượng lớn hơn 0");
						$("#qty").val("1");
						return false;
					}
					total = pro_qty * pro_price;
					$("#total_one").text(total);
					
					$("#check_order_form").attr("action","index.php?mod=order&act=add_ses_cart&pid="+pro_id+"&cid="+<?php echo $data['id']; ?>);
				});
			});
	   </script>
        <p class="oder">Tổng tiền: <span id="total"><?php echo @number_format($total)." VNĐ" ;?></span></p>
        <br>
        <div class="notes">
          <h3>Ghi chú</h3>
          <textarea name="" id="cart_message" cols="" rows="5"><?php echo $data['info']['ghichu']; ?></textarea>
        </div>
      </div>
    </form>
    <ul class="add">
      <!--li><a href="<?php echo base_url."index.php?mod=order&act=add_send_cart"?>">Thêm</a></li-->
      <li><a href="javascript:void(0)" id="send_all">Lưu</a></li>
      <li><a href="javascript:window.print();">In</a></li>
      <li><a href="<?php echo base_url; ?>">Thoát</a></li>
    </ul>
  </div>
</div>

<script type="text/javascript">
	//Send cart
	$(document).ready(function(){
		$("#send_all").click(function(){
			cart_name		= $("#order_user").val();
			cart_table		= $("#order_table").val();
			cart_message	= $("#cart_message").val();
			total  			= $("#total_cate_price").val();
			//alert(cart_table);
			val = "abc";
			$.ajax({
				"url"	: "index.php?mod=order&act=add_send_cart",
				"type"	: "post",
				"data"	: "cart_name="+cart_name+"&cart_table="+cart_table+"&cart_message="+cart_message+"&cart_total="+total+"&cid="+<?php echo $data['id']; ?>+"&type="+val,
				"async"	: "false",
				beforeSend : function(){
					$(".cart_view").html("Đang load dữ liệu ...");
				},
				success: function(results_cart){
						//$(".cart_view").html(results_cart);
						//return false;
						$(".cart_view").css("color","#639537").html("Đơn hàng của bạn đã được lưu lại !.");
						$(".bachnx_all_row").hide();
						$('body,html').animate({scrollTop:120},100);
						$("#total").text("0 VNĐ");
						$("#order_table").val("");
						$("#cart_message").val("");
				}
			})
			return false;
		});
	});
	
</script>
